package com.freesky.biz.citic.controller;

import com.freesky.biz.citic.domain.TCiticNew;
import com.freesky.biz.citic.domain.TCiticNewEnroll;
import com.freesky.biz.citic.service.ICiticNewService;
import com.freesky.common.annotation.Log;
import com.freesky.common.annotation.RepeatSubmit;
import com.freesky.common.core.controller.BaseController;
import com.freesky.common.core.domain.AjaxResult;
import com.freesky.common.core.page.TableDataInfo;
import com.freesky.common.enums.BusinessType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 中信富贵新客礼
 */
@RestController
@RequestMapping("/citic/new")
public class CiticNewController extends BaseController {

    @Autowired
    private ICiticNewService citicNewService;

    /**
     * 信运抢券列表
     */
    @PreAuthorize("@ss.hasPermi('citic:new:list')")
    @GetMapping("/list")
    public TableDataInfo list(TCiticNew citicNew) {
        startPage();
        List<TCiticNew> list = citicNewService.findList(citicNew);
        return getDataTable(list);
    }

    @Log(title = "富贵新客礼", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('citic:new:export')")
    @GetMapping("/export")
    public AjaxResult export(TCiticNew citicNew,
                             HttpServletResponse response) {
        return citicNewService.exportFile(citicNew);
    }

    @PreAuthorize("@ss.hasPermi('citic:new:list')")
    @GetMapping("/enrollList")
    public TableDataInfo enrollList(TCiticNewEnroll citicNewEnroll) {
        startPage();
        List<TCiticNewEnroll> list = citicNewService.selectEnrollList(citicNewEnroll);
        return getDataTable(list);
    }

    @Log(title = "富贵新客礼", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('citic:new:export')")
    @GetMapping("/enrollExport")
    public AjaxResult enrollExport(TCiticNewEnroll citicNewEnroll,
                             HttpServletResponse response) {
        return citicNewService.exportEnrollFile(citicNewEnroll);
    }

    @Log(title = "富贵新客礼", businessType = BusinessType.UPDATE)
    @PreAuthorize("@ss.hasPermi('citic:new:edit')")
    @RepeatSubmit
    @PostMapping("/updateRechargeById")
    public AjaxResult updateRechargeById(@Validated @RequestBody TCiticNew citicNew,
                             HttpServletResponse response) {
        citicNew.setProcessed("4");
        citicNewService.updateRechargeById(citicNew.getProcessed(),citicNew.getId());
        return AjaxResult.success();
    }
}
